package com.cheng.fmmall.controller;

import com.cheng.fmmall.service.UserService;
import com.cheng.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
@Api(value = "用户管理")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 用户注册
     * @param username
     * @param password
     * @return
     */
    @ApiOperation("用户注册")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "username", value = "用户注册账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "password", value = "用户注册密码", required = true)
    })
    @PostMapping("/regist")
    public ResultVO userRegist(String username, String password) {
        ResultVO resultVO = userService.userRegist(username, password);
        return resultVO;
    }

    /**
     * 用户登陆
     * @param username
     * @param password
     * @return
     */
    @ApiOperation("用户登陆")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "username", value = "用户登陆账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "password", value = "用户登陆密码", required = true)
    })
    @PostMapping("/login")
    public ResultVO login(String username, String password) {
        ResultVO resultVO = userService.checkLogin(username, password);
        return resultVO;
    }

}
